package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.StaffService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/sys/staff")
@CrossOrigin
@Api(value = "职员管理", description = "职员管理")
public class StaffController {

    private final StaffService staffService;

    public StaffController(StaffService staffService) {
        this.staffService = staffService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增职员接口",notes = "新增职员接口")
    public LogicResponse save(@RequestBody @Validated StaffCreateDTO staffCreateDTO) {
        staffService.save(staffCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改职员接口",notes = "修改职员接口")
    public LogicResponse update(@RequestBody @Validated StaffUpdateDTO staffUpdateDTO) {
        staffService.update(staffUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查询单个职员详情")
    public LogicResponse detail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(staffService.getStaffDetail(baseIdDTO));
    }

    @ApiOperation(value = "删除职员接口",notes = "删除职员接口")
    @PostMapping("/delete")
    public LogicResponse delete(@RequestBody @Validated StaffDeleteDTO staffDeleteDTO) {
        staffService.delete(staffDeleteDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询职员列表接口",notes = "查询职员列表接口")
    public LogicResponse queryRolePage(@RequestBody @Validated StaffQueryDTO staffQueryDTO) {
        return LogicResponse.success(staffService.getStaffList(staffQueryDTO));
    }

    @PostMapping("/set/study/model")
    @ApiOperation(value = "设置学习模式",notes = "设置学习模式")
    public LogicResponse setStudyModel(@RequestBody @Validated StudyModelDTO studyModelDTO,
                                       HttpServletRequest request) {
        staffService.setStudyModel(studyModelDTO,request);
        return LogicResponse.success("success");
    }

    @PostMapping("/set/subscribe/model")
    @ApiOperation(value = "设置订阅消息模式",notes = "设置订阅消息模式")
    public LogicResponse setSubscribeModel(@RequestBody @Validated SubscribeModelDTO subscribeModelDTO,
                                       HttpServletRequest request) {
        staffService.setSubscribeModel(subscribeModelDTO,request);
        return LogicResponse.success("success");
    }

    @PostMapping("/change/phone")
    @ApiOperation(value = "更换手机号",notes = "更换手机号")
    public LogicResponse setPhone(@RequestBody @Validated PhoneChangeDTO phoneChangeDTO,
                                           HttpServletRequest request) {
        staffService.setPhone(phoneChangeDTO,request);
        return LogicResponse.success("success");
    }

    @PostMapping("/set/head/image")
    @ApiOperation(value = "设置头像",notes = "设置头像")
    public LogicResponse setHeadImage(@RequestBody @Validated HeadImageDTO headImageDTO) {
        staffService.setHeadImage(headImageDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/set/read/product/password")
    public LogicResponse setProductReadPassword(@RequestBody @Validated SetProductReadPasswordDTO setProductReadPasswordDTO) {
        staffService.setProductReadPassword(setProductReadPasswordDTO);
        return LogicResponse.success("success");
    }


}
